<?php 
    session_start();
    if(!isset($_SESSION['islogined'])||@$_SESSION['idposition']==3)
        header("location:./Login.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link href="app.css" rel="stylesheet">
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

</head>
<body>
    <?php include 'header1.php'; ?>
    <div class="container">
        <ol class="breadcrumb path-nav">
            <li><a href="./Home.php">Home</a></li>
            <li class="active">Module Management</li>
        </ol>
    </div>
    <div class="container">
        <div class="col-md-2">
            <button id='add_new_module' class="btn btn-default">
            <span class="glyphicon glyphicon-plus"> </span>
            Add New Module</button>
            
        </div>
        <div class="col-md-1 col-md-offset-8 ">
             <button id='module_modify' class="btn btn-default">Modify</button>                    
        </div> 
        <div class="col-md-1 ">
             <button id='module_delete_show' class="btn btn-default">Delete</button>                    
        </div>           
    </div>
    <div class="container module-table">
        <?php
          include 'infor_module.php';
          show_all();
        ?>
    </div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

</div>
<script src="jquery-3.0.0.min.js"></script>
<script src="bootstrap.min.js"></script>
<script>
    $(function(){
        $("#add_new_module").click(function(){
            $(window).attr('location','AddModule.php');
        });
        $(".module").click(function(){
            $(".module").removeClass("template-level-3");
            $(this).addClass("template-level-3");
        });
        $(document).on('click','#module_modify',function(){
            var code=$(".template-level-3").data('id');
            $.post("infor_module.php",{
                type:'modify_box_show',
                code:code
            },function(data){
                $('#myModal').html(data);
                $('#myModal').modal();
            });
        });
        $(document).on('click','#module_delete_show',function(){
            var code=$(".template-level-3").data('id');
            $.post("infor_module.php",{
                type:'delete_box_show',
                code:code
            },function(data){
                $('#myModal').html(data);
                $('#myModal').modal();
            });
        })
        $(document).on('click','#delete_module_btn',function(){
            var code=$(this).data('id');
            $.post("infor_module.php",{
                type:'delete_module',
                code:code
            },function(){
                $('#'+code).hide();
            });
        })
        $(document).on('click','#modify_module_btn',function(){
            var code=$(this).data('id');
            var title=$('#title').val();
            var Semster=$('#Semster').val();
            var lecture=$('#lecture').val();
            var tutorial=$('#tutorial').val();
            var lab=$('#lab').val();
            var credit=$('#credit').val();
            var studentnum=$('#studentnum').val();
            $.post("infor_module.php",{
                type:'modify_module',
                code:code,
                title:title,
                Semster:Semster,
                lecture:lecture,
                tutorial:tutorial,
                lab:lab,
                credit:credit,
                studentnum:studentnum
            },function(data){
                $('.success-coin').remove();
                $('#'+code).html(data);
            });
        });
    });
</script>
</body>
</html>